package ru.urfc.portal.ui.client.renderers.colorers;

import ru.urfc.portal.ui.client.EnumRegistry;
import ru.urfc.portal.ui.client.Style;
import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.model.catalogs.CatalogItemWithStyle;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

public class CatalogItemColorer extends BaseColorer {
	protected GridField codeField;
	protected Class<? extends CatalogItemWithStyle> klass;
	
	public CatalogItemColorer(GridField textField, GridField codeField, Class<? extends CatalogItemWithStyle> klass, Element element, Style style) {
		super(textField, element, style);
		this.codeField = codeField;
		this.klass = klass;
	}

	@Override
	public void colorElements(ModelData modelData) {		
		String code = codeField.getValue(modelData);
		String text = field.getValue(modelData);
		if (code != null && text != null) {
			CatalogItemWithStyle item = EnumRegistry.getCatalogItem(klass, code, text);
			element.setClassName(item.getStyleName(style));
		}
	}

}
